function cal1Leg(matchno, betUnit) {	
	
	return HDClegArr[matchno-1][0] * betUnit + HDClegArr[matchno-1][1] * betUnit


}

function cal2Leg(matchno, betUnit) {

	m1 = matchno.substr(0, 1)
	m2 = matchno.substr(1, 1)	
	tdiv = 0
	for (var a=0;a<=1;a++) {
		for (var b=0;b<=1;b++) {			
			tdiv += HDClegArr[m1-1][a] * HDClegArr[m2-1][b] * betUnit
		}
	}
	return tdiv
}

function cal3Leg(matchno, betUnit) {
	m1 = matchno.substr(0, 1)
	m2 = matchno.substr(1, 1)
	m3 = matchno.substr(2, 1)
	
	//alert(HDClegArr[0][0]) //1.89
	//alert(HDClegArr[0][1])
	//alert(HDClegArr[1][0])	//1.93
	//alert(HDClegArr[1][1])
	//alert(HDClegArr[2][0]) //1
	//alert(HDClegArr[2][1]) //1.9
	
	tdiv = 0
	for (var a=0;a<=1;a++) {
		for (var b=0;b<=1;b++) {		
			for (var c=0;c<=1;c++) {
				tdiv += HDClegArr[m1-1][a] * HDClegArr[m2-1][b] * HDClegArr[m3-1][c] * betUnit
			}
		}
	}
	
	return tdiv
}

function cal4Leg(matchno, betUnit) {
	m1 = matchno.substr(0, 1)
	m2 = matchno.substr(1, 1)
	m3 = matchno.substr(2, 1)
	m4 = matchno.substr(3, 1)
	
	
	tdiv = 0
	for (var a=0;a<=1;a++) {
		for (var b=0;b<=1;b++) {		
			for (var c=0;c<=1;c++) {
				for (var d=0;d<=1;d++) {
					tdiv += HDClegArr[m1-1][a] * HDClegArr[m2-1][b] * HDClegArr[m3-1][c] * HDClegArr[m4-1][d] * betUnit
				}
			}
		}
	}
	
	return tdiv
}

function cal5Leg(matchno, betUnit) {
	m1 = matchno.substr(0, 1)
	m2 = matchno.substr(1, 1)
	m3 = matchno.substr(2, 1)
	m4 = matchno.substr(3, 1)
	m5 = matchno.substr(4, 1)
	
	tdiv = 0
	for (var a=0;a<=1;a++) {
		for (var b=0;b<=1;b++) {		
			for (var c=0;c<=1;c++) {
				for (var d=0;d<=1;d++) {
					for (var e=0;e<=1;e++) {
						tdiv += HDClegArr[m1-1][a] * HDClegArr[m2-1][b] * HDClegArr[m3-1][c] * HDClegArr[m4-1][d] * HDClegArr[m5-1][e] * betUnit
					}
				}
			}
		}
	}
	
	return tdiv
}

function cal6Leg(matchno, betUnit) {
	m1 = matchno.substr(0, 1)
	m2 = matchno.substr(1, 1)
	m3 = matchno.substr(2, 1)
	m4 = matchno.substr(3, 1)
	m5 = matchno.substr(4, 1)
	m6 = matchno.substr(5, 1)
	
	tdiv = 0
	for (var a=0;a<=1;a++) {
		for (var b=0;b<=1;b++) {		
			for (var c=0;c<=1;c++) {
				for (var d=0;d<=1;d++) {
					for (var e=0;e<=1;e++) {
						for (var f=0;f<=1;f++) {
							tdiv += HDClegArr[m1-1][a] * HDClegArr[m2-1][b] * HDClegArr[m3-1][c] * HDClegArr[m4-1][d] * HDClegArr[m5-1][e] * HDClegArr[m6-1][f] * betUnit
						}
					}
				}
			}
		}
	}	
	return tdiv
}

function cal7Leg(matchno, betUnit) {
	m1 = matchno.substr(0, 1)
	m2 = matchno.substr(1, 1)
	m3 = matchno.substr(2, 1)
	m4 = matchno.substr(3, 1)
	m5 = matchno.substr(4, 1)
	m6 = matchno.substr(5, 1)
	m7 = matchno.substr(6, 1)
	
	tdiv = 0
	for (var a=0;a<=1;a++) {
		for (var b=0;b<=1;b++) {		
			for (var c=0;c<=1;c++) {
				for (var d=0;d<=1;d++) {
					for (var e=0;e<=1;e++) {
						for (var f=0;f<=1;f++) {
							for (var g=0;g<=1;g++) {
								tdiv += HDClegArr[m1-1][a] * HDClegArr[m2-1][b] * HDClegArr[m3-1][c] * HDClegArr[m4-1][d] * HDClegArr[m5-1][e] * HDClegArr[m6-1][f] * HDClegArr[m7-1][g] * betUnit
							}
						}
					}
				}
			}
		}
	}	
	return tdiv
}

function cal8Leg(matchno, betUnit) {
	m1 = matchno.substr(0, 1)
	m2 = matchno.substr(1, 1)
	m3 = matchno.substr(2, 1)
	m4 = matchno.substr(3, 1)
	m5 = matchno.substr(4, 1)
	m6 = matchno.substr(5, 1)
	m7 = matchno.substr(6, 1)
	m8 = matchno.substr(7, 1)
	
	tdiv = 0
	for (var a=0;a<=1;a++) {
		for (var b=0;b<=1;b++) {		
			for (var c=0;c<=1;c++) {
				for (var d=0;d<=1;d++) {
					for (var e=0;e<=1;e++) {
						for (var f=0;f<=1;f++) {
							for (var g=0;g<=1;g++) {
								for (var h=0;h<=1;h++) {
									tdiv += HDClegArr[m1-1][a] * HDClegArr[m2-1][b] * HDClegArr[m3-1][c] * HDClegArr[m4-1][d] * HDClegArr[m5-1][e] * HDClegArr[m6-1][f] * HDClegArr[m7-1][g] * HDClegArr[m8-1][h] * betUnit
								}
							}
						}
					}
				}
			}
		}
	}	
	return tdiv
}
